package com.panda.resource.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.panda.common.annotation.Log;
import com.panda.common.core.controller.BaseController;
import com.panda.common.core.domain.AjaxResult;
import com.panda.common.enums.BusinessType;
import com.panda.resource.domain.PandaFile;
import com.panda.resource.service.IPandaFileService;
import com.panda.common.utils.poi.ExcelUtil;
import com.panda.common.core.page.TableDataInfo;

/**
 * 文件管理Controller
 * 
 * @author panda
 * @date 2021-01-10
 */
@RestController
@RequestMapping("/resource/file")
public class PandaFileController extends BaseController
{
    @Autowired
    private IPandaFileService pandaFileService;

    /**
     * 查询文件管理列表
     */
    @PreAuthorize("@ss.hasPermi('resource:file:list')")
    @GetMapping("/list")
    public TableDataInfo list(PandaFile pandaFile)
    {
        startPage();
        List<PandaFile> list = pandaFileService.selectPandaFileList(pandaFile);
        return getDataTable(list);
    }

    /**
     * 导出文件管理列表
     */
    @PreAuthorize("@ss.hasPermi('resource:file:export')")
    @Log(title = "文件管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(PandaFile pandaFile)
    {
        List<PandaFile> list = pandaFileService.selectPandaFileList(pandaFile);
        ExcelUtil<PandaFile> util = new ExcelUtil<PandaFile>(PandaFile.class);
        return util.exportExcel(list, "file");
    }

    /**
     * 获取文件管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('resource:file:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(pandaFileService.selectPandaFileById(id));
    }

    /**
     * 新增文件管理
     */
    @PreAuthorize("@ss.hasPermi('resource:file:add')")
    @Log(title = "文件管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PandaFile pandaFile)
    {
        return toAjax(pandaFileService.insertPandaFile(pandaFile));
    }

    /**
     * 修改文件管理
     */
    @PreAuthorize("@ss.hasPermi('resource:file:edit')")
    @Log(title = "文件管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PandaFile pandaFile)
    {
        return toAjax(pandaFileService.updatePandaFile(pandaFile));
    }

    /**
     * 删除文件管理
     */
    @PreAuthorize("@ss.hasPermi('resource:file:remove')")
    @Log(title = "文件管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pandaFileService.deletePandaFileByIds(ids));
    }
}
